/*
 * @Description: 
 * @Author: paddies
 * @Date: 2024-07-03 11:02:25
 * @LastEditors: paddies
 * @LastEditTime: 2025-09-30 01:24:04
 * @FilePath: /shared_components/lib/luntai-components/build-dynamic-info/buildDynamicInfo.dart
 */
import 'package:flutter/material.dart';
import 'package:shared_components/build-button/buildButton.dart';
import 'package:shared_components/build-common/buildCommon.dart';
import 'package:shared_components/build-image/buildImage.dart';
import 'package:shared_components/build-upload/buildUpload.dart';
import 'package:url_launcher/url_launcher.dart';

Widget buildDynamicInfo(
    {List list = const [],
    double paddingLeft = 10,
    double paddingRight = 10,
    double paddingTop = 10,
    double paddingBottom = 10}) {
  var defauleColor = Color(0xff000000);
  var defaultBtnColor = Color(0xff0000eb);
  return Column(
    children: [
      ...list.map((e) {
        var mainAxisAlignment = MainAxisAlignment.start;
        if (showText(e["align"]) == 'left') {
          mainAxisAlignment = MainAxisAlignment.start;
        }
        if (showText(e["align"]) == 'right') {
          mainAxisAlignment = MainAxisAlignment.end;
        }
        if (showText(e["align"]) == 'space-between') {
          mainAxisAlignment = MainAxisAlignment.spaceBetween;
        }
        var img = showText(e["img"]);
        if (img == 'true') {
          var imgs = showText(e["value"]).split(",");
          return Container(
              width: double.infinity,
              // height: 50,
              // color: Colors.red,
              color: Colors.white,
              padding:
                  EdgeInsets.only(top: 10, bottom: 10, left: 10, right: 10),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    showText(e["name"]),
                    style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  buildUpload(
                      type: "watch",
                      list: imgs,
                      onChange: (type, value, index) {
                        // if (type == 'add') {
                        //   controller.state.imgUrls.add(value);
                        // }
                        // if (type == 'del') {
                        //   controller.state.imgUrls.removeAt(index);
                        // }
                        // if (type == 'change') {
                        //   controller.state.imgUrls[index] = value;
                        // }
                      }),
                ],
              ));
        }
        // if (showText(e["type"]) == 'phone') {
        //   return Container(
        //     width: double.infinity,
        //     height: 50,
        //     color: Colors.white,
        //     padding: EdgeInsets.only(top: 5, bottom: 5, left: 10, right: 10),
        //     child: Row(
        //       mainAxisAlignment: mainAxisAlignment,
        //       children: [
        //         Expanded(
        //             child: buildButton(title: "联系用户", borderRadius: 5, colors: [
        //           e["color"] == ""
        //               ? defaultBtnColor
        //               : Color(
        //                   int.parse('0xff' +
        //                       showText(e["color"].replaceAll("#", ""))),
        //                 ),
        //           e["color"] == ""
        //               ? defaultBtnColor
        //               : Color(
        //                   int.parse('0xff' +
        //                       showText(e["color"].replaceAll("#", ""))),
        //                 ),
        //         ]))

        //         // Text(
        //         //   showText(e["name"]),
        //         //   style: TextStyle(fontSize: 14),
        //         // ),
        //         // Visibility(
        //         //     child: Text(
        //         //   showText(e["value"]),
        //         //   style: TextStyle(
        //         //     fontSize: 14,
        //         //     color: showText(e["color"]) == ""
        //         //         ? defauleColor
        //         //         : Color(
        //         //             int.parse('0xff' +
        //         //                 showText(e["color"].replaceAll("#", ""))),
        //         //           ),
        //         //   ),
        //         // ))
        //       ],
        //     ),
        //   );
        // }
        return Container(
          width: double.infinity,
          // height: 50,
          // color: Colors.yellow,
          padding: EdgeInsets.only(
              top: paddingTop,
              bottom: paddingBottom,
              left: paddingLeft,
              right: paddingRight),
          child: Row(
            mainAxisAlignment: mainAxisAlignment,
            children: [
              Text(
                showText(e["name"]),
                style: TextStyle(fontSize: 14),
              ),
              Text(
                showText(e["value"]),
                style: TextStyle(
                  fontSize: 14,
                  color: showText(e["color"]) == ""
                      ? defauleColor
                      : Color(
                          int.parse('0xff' +
                              showText(e["color"].replaceAll("#", ""))),
                        ),
                ),
              ),
              if (showText(e["type"]) == 'phone')
                Visibility(
                    visible: showText(e["type"]) == 'phone',
                    child: Container(
                        margin: EdgeInsets.only(left: 10),
                        width: 100,
                        height: 30,
                        child: buildButton(
                            title: showText(e["phoneMsg"]),
                            onClick: () {
                              launch('tel:' + showText(e["value"]));
                            },
                            fontSize: 14,
                            borderRadius: 5,
                            colors: [
                              e["color"] == ""
                                  ? defaultBtnColor
                                  : Color(
                                      int.parse('0xff' +
                                          showText(
                                              e["color"].replaceAll("#", ""))),
                                    ),
                              e["color"] == ""
                                  ? defaultBtnColor
                                  : Color(
                                      int.parse('0xff' +
                                          showText(
                                              e["color"].replaceAll("#", ""))),
                                    ),
                            ])))
            ],
          ),
        );
      })
    ],
  );
}
